package com.example.dirviesystem.coach.service;

import com.example.dirviesystem.entity.CoachInform;
import com.example.dirviesystem.entity.CoachMessage;
import com.example.dirviesystem.repository.CoachInformRepository;
import com.example.dirviesystem.repository.CoachMessageRe;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;

@Service
public class CoachInformService {

    @Autowired
    private CoachMessageRe coachMessageRe;

    public Page<CoachMessage> findInformsByCoachId(Long coachId, LocalDate startDate, LocalDate endDate, PageRequest pageable) {
        LocalDateTime startDateTime = startDate != null ? startDate.atStartOfDay() : null;
        LocalDateTime endDateTime = endDate != null ? endDate.plusDays(1).atStartOfDay() : null;


        return coachMessageRe.findByCoachIdAndDateRange(
                coachId,
                startDateTime,
                endDateTime,
                pageable);
    }

    public CoachMessage saveInform(CoachMessage inform) {
        return coachMessageRe.save(inform);
    }

    public CoachMessage findById(Long id) {
        return coachMessageRe.findById(id).orElse(null);
    }


}